package com.example.mpandroidchart1107;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.Paint;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.SeekBar;
import android.widget.TextView;

import com.github.mikephil.charting.charts.CandleStickChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.CandleData;
import com.github.mikephil.charting.data.CandleDataSet;
import com.github.mikephil.charting.data.CandleEntry;
import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;

import java.util.ArrayList;
import java.util.List;

public class Main6Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main6);
        CandleStickChart chart = findViewById(R.id.chart1);
        CandleDataSet dataset = getDataset("test");
        dataset.setShadowColor(Color.DKGRAY);
        dataset.setShadowWidth(1.0f);
        dataset.setDecreasingColor(Color.RED);
        dataset.setDecreasingPaintStyle(Paint.Style.FILL);
        dataset.setIncreasingColor(Color.rgb(12, 242, 84));
        dataset.setIncreasingPaintStyle(Paint.Style.FILL);
        CandleData data = new CandleData(dataset);
        chart.setData(data);
        chart.invalidate();
    }

    private CandleDataSet getDataset(String title) {
        List<CandleEntry> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            float high = 50.0f + ((float) Math.random() * 30f);
            float low = 50.0f - ((float) Math.random() * 30f);
            float diff = high - low;
            float open = high - diff * 0.8f * ((float) Math.random());
            float close = high - diff * 0.8f * ((float) Math.random());
            Log.e("----->", "high=" + high + ",low=" + low + ",open=" + open + ",close=" + close);
            CandleEntry entry = new CandleEntry(i, high, low, open, close);
            list.add(entry);
        }
        return new CandleDataSet(list, title);
    }
}